package com.party.core.service.notify.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.UUIDUtils;
import com.party.core.dao.read.notify.NotifySysMessageMemberReadDao;
import com.party.core.dao.write.notify.NotifySysMessageMemberWriteDao;
import com.party.core.model.notify.NotifySysMessageMember;
import com.party.core.service.notify.INotifySysMessageMemberService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * 系统消息推送对象关系服务接口实现
 *
 * @author yifeng
 * @date 2018/6/25 0025
 * @time 上午 11:12
 */
@Service
public class NotifySysMessageMemberService implements INotifySysMessageMemberService {
    @Autowired
    private NotifySysMessageMemberReadDao notifySysMessageMemberReadDao;
    @Autowired
    private NotifySysMessageMemberWriteDao notifySysMessageMemberWriteDao;

    @Override
    public String insert(NotifySysMessageMember sysMessageMember) {
        sysMessageMember.setId(UUIDUtils.generateRandomUUID());
        boolean result = notifySysMessageMemberWriteDao.insert(sysMessageMember);
        if (result) {
            return sysMessageMember.getId();
        }
        return null;
    }

    @Override
    public boolean update(NotifySysMessageMember sysMessageMember) {
        return false;
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return notifySysMessageMemberWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return false;
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return notifySysMessageMemberWriteDao.batchDelete(ids);
    }

    @Override
    public NotifySysMessageMember get(String id) {
        return notifySysMessageMemberReadDao.get(id);
    }

    @Override
    public List<NotifySysMessageMember> listPage(NotifySysMessageMember sysMessageMember, Page page) {
        return notifySysMessageMemberReadDao.listPage(sysMessageMember, page);
    }

    @Override
    public List<NotifySysMessageMember> list(NotifySysMessageMember sysMessageMember) {
        return notifySysMessageMemberReadDao.listPage(sysMessageMember, null);
    }

    @Override
    public List<NotifySysMessageMember> batchList(Set<String> ids, NotifySysMessageMember sysMessageMember, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return notifySysMessageMemberReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public List<NotifySysMessageMember> findByMessageId(String sysMessageId) {
        NotifySysMessageMember messageMember = new NotifySysMessageMember();
        messageMember.setSysMessageId(sysMessageId);
        return notifySysMessageMemberReadDao.listPage(messageMember, null);
    }
}
